package com.xxx.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 消息发送拦截器，拦截各版块中需要发消息的方法
 * @author TL
 * 
 */
@Aspect
public class MessageAspect {
	
    /**
     * 筛选方法
     *
     */
    @Pointcut("execution(* com.xxx.service.FilmService.insertFilm(..))")
    public void methodCall() { }
    
    @Pointcut("execution(* com.xxx.service.FilmServiceImpl.test(..))")
    public void testMethodCall() { }
    
    @AfterReturning(value="testMethodCall()", argNames="rtv", returning="rtv")
    public void afterCalls(JoinPoint joinPoint, Object rtv) throws Throwable{
    	
    	System.out.println("afterCalls...1");
    	
    	Signature sign = joinPoint.getSignature();
    	
    	String name = sign.getName();
    	
    	System.out.println(name);
    	
    	/*for (int i = 0; i < joinPoint.getArgs().length; i++) {  
            Object arg = joinPoint.getArgs()[i];  
            if(null != arg) {  
                System.out.println("Args:" + arg.getClass().getName());   
            }  
        }*/
    	
    	//System.out.println(rtv.getClass().getName());
    	
    	System.out.println("afterCalls...2");
    }
    

	/**
	 * 环绕通知，方法切面业务逻辑的处理。
	 * @param joinPoint
	 * @return
	 * @throws Throwable
	 */
//    @Around("loggableCalls()")
//	public Object aroundLogCalls(ProceedingJoinPoint joinPoint)
//			throws Throwable {
//		System.out.println("在调用方法:"
//				+ joinPoint.getSignature().getName() + "之前");
//		Object object = joinPoint.proceed();
//		System.out.println("在调用方法:"
//				+ joinPoint.getSignature().getName() + "之后");
//		return object;
//	}
    
    /**
     * 功能；在方法执行前执行的代码
     */
    /*@Before(value="printCall() && args(str)", argNames="str")
	public void printLogInfo(String str){
    	System.out.println("[开始日志记录-方法前置通知！]方法参数：" + str);
    }*/
    
    
    
}





